package com.unionftech.common.common.api

import com.unionftech.baselibrary.network.RetrofitClient
import com.unionftech.common.CommonConstants

class CommonApiManager {
    private lateinit var languageApi: LanguageApi
    private lateinit var commonApi: CommonApi

    companion object {
        @Volatile
        private var instance: CommonApiManager? = null

        @JvmStatic
        fun getInstance() = instance ?: synchronized(this) {
            instance ?: CommonApiManager().also {
                instance = it
            }
        }
    }

    fun apiLanguage(): LanguageApi {
        if (!::languageApi.isInitialized) {
            val client = RetrofitClient.getInstance()
            languageApi = client
                .createBaseUrl(
                    LanguageApi::class.java,
                    client.getNetWork().getUrlMap()[CommonConstants.Key.KEY_ASSETS_URL] ?: ""
                )
        }
        return languageApi
    }

    fun apiCommon(): CommonApi {
        if (!::commonApi.isInitialized) {
            val client = RetrofitClient.getInstance()
            commonApi = client
                .create(
                    CommonApi::class.java,
                )
        }
        return commonApi
    }
}